﻿using ConfExpert.Forms.Base;
using System;
using System.Drawing;
using System.IO;

namespace ITaskManager.Forms.IT
{
    public partial class ImageViewer : XPopupForm
    {
        byte[] data;
        int tip;

        public ImageViewer(byte[] data, int tip = 0)
        {
            InitializeComponent();
            this.data = data;
            this.tip = tip;
        }

        public Bitmap ToBitmap(byte[] bytes)
        {
            Bitmap bitmap = null;
            using (MemoryStream ms = new MemoryStream(bytes))
            {
                bitmap = (Bitmap)Image.FromStream(ms);
            }
            return bitmap;
        }

        private void ImageViewer_Load(object sender, EventArgs e)
        {
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            if (tip == 0) //JPG
            {
                jpgViewer.Image = ToBitmap(data);
                pdfViewer.Visible = false;
            }
            else
            {
                jpgViewer.Visible = false;
                pdfViewer.LoadDocument(new MemoryStream(data));
            }
        }
    }
}
